//
//  HomePageCollectionDetailViewController.m
//  InSuger
//
//  Created by dllo on 15/11/30.
//  Copyright © 2015年 Dior_3g. All rights reserved.
//

#import "HomePageCollectionDetailViewController.h"

@interface HomePageCollectionDetailViewController ()<UIWebViewDelegate>

@property(nonatomic, retain)UIActivityIndicatorView *activityIndicatorView;

@end

@implementation HomePageCollectionDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.title = @"本期话题";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    
    
    //      风火轮
    self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 32.0f, 32.0f)];
    self.activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
    self.activityIndicatorView.center = self.view.center;
    [self.view addSubview:self.activityIndicatorView];
    
    
    //      webView的创建
    UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:webView];

    
    UIScrollView *tempView=(UIScrollView *)[webView.subviews objectAtIndex:0];
    tempView.bounces = NO;
    
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).with.offset(- HEIGHT / 100 * 7);
        make.size.mas_equalTo(self.view);
        
    }];
    
    webView.delegate  = self;
    webView.scalesPageToFit = YES;
    
    @weakify(webView);
    [self addColorChangedBlock:^{
        @strongify(webView);
        webView.nightBackgroundColor = UIColorFromRGB(0x343434);
    }];

    
    NSLog(@"%@", self.model.share_url);
    NSURL *url = [NSURL URLWithString:self.model.share_url];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [webView loadRequest:request];
    
}


#pragma mark    风火轮的开始与结束
- (void)webViewDidStartLoad:(UIWebView *)webView {
    
    [self.activityIndicatorView startAnimating];
    
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    
    [self.activityIndicatorView stopAnimating];
    
    [self.activityIndicatorView removeFromSuperview];
    
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('.wrapper').style.background-color='#FF0000'"];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
